"""
检查图像生成记录的字段信息
"""
from django.core.management.base import BaseCommand
from ai_image.models import ImageGeneration


class Command(BaseCommand):
    help = '检查图像生成记录的所有字段信息'

    def handle(self, *args, **options):
        # 获取模型的所有字段
        fields = ImageGeneration._meta.get_fields()
        
        self.stdout.write(self.style.SUCCESS('=== ImageGeneration 模型字段列表 ==='))
        self.stdout.write(f'总共 {len(fields)} 个字段:\n')
        
        for field in fields:
            field_name = field.name
            field_type = field.__class__.__name__
            
            # 获取字段的verbose_name
            verbose_name = getattr(field, 'verbose_name', field_name)
            
            # 获取字段的help_text
            help_text = getattr(field, 'help_text', '')
            
            self.stdout.write(f'  • {field_name} ({field_type})')
            self.stdout.write(f'    中文名: {verbose_name}')
            if help_text:
                self.stdout.write(f'    说明: {help_text}')
            self.stdout.write('')
        
        # 检查数据库中的记录数量
        total_count = ImageGeneration.objects.count()
        self.stdout.write(self.style.SUCCESS(f'数据库中共有 {total_count} 条图像生成记录'))
        
        # 显示最新的几条记录信息
        if total_count > 0:
            latest_records = ImageGeneration.objects.order_by('-created_at')[:3]
            self.stdout.write(self.style.SUCCESS('\n=== 最新的3条记录 ==='))
            
            for record in latest_records:
                self.stdout.write(f'\nID: {record.id}')
                self.stdout.write(f'用户: {record.user.username}')
                self.stdout.write(f'提示词: {record.prompt[:50]}...')
                self.stdout.write(f'生成类型: {record.get_generation_type_display_cn()}')
                self.stdout.write(f'质量: {record.get_quality_display_cn()}')
                self.stdout.write(f'艺术风格: {record.art_style or "无"}')
                self.stdout.write(f'艺术家: {record.artist or "无"}')
                self.stdout.write(f'批次: B{record.batch_number}I{record.image_number}')
                self.stdout.write(f'场景尺寸: {record.scene_size or "自定义"}')
                self.stdout.write(f'语言: {record.language}')
                self.stdout.write(f'状态: {record.get_status_display()}')
                self.stdout.write(f'创建时间: {record.created_at}')
                self.stdout.write('-' * 50)